Skip to content

[PR] fix(dsh): reuse verified folds across adjacent surface generations - #8123

Open
bluesmilery wants to merge 23 commits into
ranxianglei:masterfrom
bluesmilery:2026-12-02_dsh-generation-reuse
Open

bluesmilery wants to merge 23 commits into
ranxianglei:masterfrom
bluesmilery:2026-12-02_dsh-generation-reuse

Conversation

@bluesmilery

@bluesmilery bluesmilery commented Dec 2, 2026 •

Copy link
Copy Markdown

Fixes #8125

Problem

A DSH surface replacement changes the billing/compression conversation namespace introduced in #6123. Sending the first full replay to an empty namespace can resend history that the preceding generation had already compressed. Adopting the whole parent would also hide real edits or expose stale tool results.

Change

On the first full replay of an empty child, copy only complete folds from the immediately preceding generation of the same DSH session and upstream. Check original wire-unit content and order, complete tool pairs, protected recent messages, nested dependencies, citations, original text and content-store bindings. Persist accepted folds under the target lock before preparing the first upstream request. A miss keeps the raw messages; an existing child or a legacy ledger without evidence is never backfilled. No extra summary call, history rewrite or change to either compaction engine.

The adapter stamps the owner only on attributed main dispatches carrying host message IDs. The local proxy consumes that header; it does not reach the model. Scope is OpenAI Chat and Anthropic Messages. Responses, auxiliary calls, partial deltas and the experimental egress plane are not reuse sources.

Review stack

Depends on #6123 for the DSH model/generation namespace. The base is upstream master; until #6123 lands, GitHub's Files changed tab includes the prerequisite. Review the second patch alone. Please merge the route first (or rebase this after it), not the other way around.

Config surface

No new config, no migration or automatic repair of existing ledgers.

Verification

  • Typecheck, production build and 108 focused tests on the stacked contribution head: positive and negative evidence, actual HTTP proxy first send, lookup/decompress, cold SQLite restart, concurrent retry, OpenAI/Anthropic tool pairing, and refusal to reuse on unsupported traffic.
  • 16 route-parity scenarios with real DSH 0.2.2-rc.5 Cordis, Session, token meter and native compactor; deterministic provider.
  • On the release port (v0.1.218), a clean install of the packed artifact forwarded the stored summary on the first child request and recovered the original via decompress; exactly two provider requests for two turns, no private header forwarded.

All histories and provider responses for these tests are synthetic.

bluesmilery and others added 19 commits November 10, 2026 20:59
The parity test compares forwarded payloads across three forked proxy arms with deepEqual, but the kernel stamps wall-clock yyyy-mm-dd hh:mm:ss timestamps into the ACP tag time= attribute and the compress tool-result block time range. Arms running on different seconds differ in those bytes alone, so the comparison flaked. Mask every wall-clock timestamp before the cross-arm comparison (same sanctioned normalization as issue5403-watermark-fastpath.test.ts).
Resolves the two doc/config conflicts from master's Japanese-docs +
config-coverage work:
- docs/architecture.md: union (keep PR's DSH native-model-policy intro
  line + master's en/zh/ja hub line).
- website/config-reference/server.yaml: keep the PR's feature-aware
  dsh section desc (wire guard refuses UNMANAGED native compaction,
  nativeCompactionModels bypasses it) over master's stale
  'refused unconditionally' wording; add the desc_ja that master's
  new gen-config-docs check-coverage now requires on every entry for
  dsh.nativeCompactionModels / .model / .provider.

No code changes; config-coverage and architecture-docs guards green.
Resolves the one code conflict in src/agent/dsh-native.ts (master moved
265 commits past the previous merge base 36a04a7):
- PluginContext.tools type: union of the PR's register {when} conditional
  (native-compaction model gating) and master's new tools.get? method.
- restoreTools register call: keep master's host-owned-lifetime structure
  (owner.ctx.tools.register(definition), ranxianglei#6702/ranxianglei#3380) and re-attach the
  PR's {when} predicate so bili tools stay hidden on native-owned models.
  definition is the same toolDefinition(tool) master pre-builds into
  owner.definitions (line 1084), so behavior is identical to the PR's
  inline registration.

Verified locally: typecheck + build green; dsh-native-compaction +
dsh-native targeted suites 83/83 pass.
…els (ranxianglei#6123)

The PR added the dsh.nativeCompactionModels seed entries and regenerated the
EN/ZH config docs, but the Japanese artifact was left stale — the docs-sync
drift guard (gen-config-docs generate + git diff --exit-code) went red on the
merge ref. This commit is the generator's own output; no manual edits.
…l-native-compaction

# Conflicts:
#	src/agent/dsh-compaction-disable.ts
…l-native-compaction

# Conflicts:
#	reference/architecture.md
#	src/agent/dsh-native.ts
# Conflicts:
#	src/agent/dsh-compaction-disable.ts
# Conflicts:
#	reference/architecture.md
#	tsup.config.ts
@ranxianglei ranxianglei changed the title fix(dsh): reuse verified folds across adjacent surface generations [PR] fix(dsh): reuse verified folds across adjacent surface generations Dec 2, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

Reviewing this stacked contribution now. Duplicate screening (查重): not a duplicate. Searched open+closed PRs/issues for the same mechanism:

Structural note for reviewers: the 35-file / +1987 PR diff includes the #6123 prerequisite. The actual second patch is a single commit e39e7907a9c — 12 files, +969/−16 (core src/dsh-generation-reuse.ts + handle/agent/store/persist wiring + tests + docs). I'm reviewing that patch alone.

Currently running typecheck + the focused test suites (unit dsh-generation-reuse, attribution, plugin-fork integration) on the stacked head; full 8-question review follows.

@bluesmilery

Copy link
Copy Markdown
Author

CI triage for the Windows cold-restart check and the separate upstream failure:

  • e238b44 fixes the test-only path assertion: the worker sets TMPDIR/TEMP/TMP to its own scratch dir, and the assertion uses the platform's path separator. The original is still read back and compared. The targeted restart test and packed-artifact round trip pass locally.
  • The other failure in all three red shards of run 46806234176 is the two variants of tests/egress-session-footprint.test.ts: no such table: eg_debug. I reproduced both on a clean, unpatched upstream master at 230753f with node --import ./tests/preload-test-env.mjs --import tsx --test tests/egress-session-footprint.test.ts. The file is absent from the v0.1.218 release tag. No bypasses or unrelated schema changes were added here.
  • Clean rebuild of the v0.1.218 release port: 254 focused tests passed, no skips, and 16 DSH rc.5 parity scenarios passed. The additional portability change affects tests only.

@bluesmilery

Copy link
Copy Markdown
Author

Confirmed on the final head e238b44: Windows / Node 22, shard 4 reports ok 1821 for the DSH cold-restart / concurrent-retry / original-content test. Its only two remaining failures are the egress-session-footprint cases reproduced on unpatched master above.

The ACP marker regex at src/dsh-generation-reuse.ts:295 used real
angle brackets, inconsistent with the dominant hex-escape convention
(\x3c/\x3e) used for ACP-tag regexes throughout the codebase
(chain-artifacts.ts, preflight.ts, tag-echo-filter.ts, etc.). KDD ranxianglei#2
requires hex escapes for ACP angle brackets in source files.

Functionally identical (tests pass 12/12); pure style consistency fix.
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷

PR #8123 审核结论 (ai: opencode/qwen3.8-27b)

查重: 不重复。 #8123 是唯一做代际折叠复用的 PR。相关但不同: #6123 (其声明的前置依赖, 引入 sid|dsh-generation:N 命名空间 + 模型路由 — 是基座, 非重复); #5962 "preserve verified seeded context inheritance" (不同机制: fork/sidechat/subagent 的 isSeeded + forkSource/parentSession 继承, 非代际重放)。

审核范围

PR diff (35 文件 / +1987) 含 #6123 前置。实际第二个补丁 = 单 commit e39e7907a9c (12 文件, +969/-16), 是真正的审核对象。

验证结果

  • typecheck: 干净 (kernel + pi-subagents + 主包, tsc 无错误)
  • 生产构建: 成功 (build-info commit=e39e7907a9c, dist-import-annotations OK, dist-external OK)
  • 定向测试: 88/88 通过
    • tests/dsh-generation-reuse.test.ts 12/12 (9 个拒因 + fail-closed 矩阵 + 嵌套 + 不支持 wire / 伪造 owner)
    • tests/dsh-llm-stream-attribution.test.ts 12/12 (头盖戳)
    • tests/plugin-fork.test.ts 64/64 (首次发送 / 查找 / 重试 plugin+proxy 车道, 进程重启大重放折叠先于窗口守卫, 并发重试, SIGKILL 崩溃恢复, decompress, openai/anthropic 真实工具对, 门控测试)
  • CI: 新 head b2a6a09373d (含我的风格修复) 正在跑, 0 失败 / 13 pending。前一个 head e238b44b3f3 (贡献者新增 2 commit) 有 3 个 test shard 失败 (ubuntu-24/3, windows-22/4, ubuntu-22/3), 日志暂不可得 (404), 待新 CI 完成确认是否复现。

顺手修 (1 处, 已 push 到 PR 分支)

  • ACP marker 正则风格 (src/dsh-generation-reuse.ts:295): 原用真实尖括号 /<acp...>/, 与代码库主导的 hex 转义约定 (\x3c/\x3e, 见 chain-artifacts.ts:20, preflight.ts:661, tag-echo-filter.ts 等) 不一致; KDD fix: address all code review findings (condense, routing, session-id, dead code) #2 要求源文件 ACP 尖括号必须 hex 转义。已改为 /\x3cacp...\x3e.../ (功能等价, 测试 12/12 通过)。commit b2a6a09373d。

结构化八问

  1. 是什么问题: DSH 的 surface.replaceGeneration (宿主持久化) 改变 bili 会话命名空间为 <sid>|dsh-generation:N ([PR] feat(dsh): route models between stock native and bili compaction #6123 引入)。向空的新命名空间发首次完整重放时, 会重发父代已压缩过的历史。本 PR 在空子代的完整重放时, 仅复用紧邻前代 (同 DSH 会话 + 同上游) 的已验证完整折叠, 避免重复压缩。

  2. 什么原因导致的: [PR] feat(dsh): route models between stock native and bili compaction #6123 引入了 DSH 代际命名空间, 但未处理代际切换时的折叠继承。本 PR 填补此缺口。

  3. 影响范围与严重程度: 仅影响 DSH 代际命名空间会话 (<sid>|dsh-generation:N) 且携带 x-bili-dsh-generation-owner 头的请求。非 DSH 会话和非代际请求不受影响。严重程度: 中 (性能优化, 避免重复压缩; 非可用性缺陷)。

  4. 怎么修复的: src/dsh-generation-reuse.ts 的 visitGeneration 在目标锁内验证父代折叠 (wire 单元内容/顺序、完整工具对、受保护消息、嵌套依赖、引用、原文与内容存储绑定), 仅复用通过验证的完整折叠。任何疑点降级为原始历史 (fail-closed)。复用后保留父代 nextBlockId/nextRunId 避免碰撞; 未验证 id 保留 ref 座位 (dsh-reserved: 前缀) 维持消息 id 不可变。

  5. 是否有回归问题: 所有变更由新条件门控 (DSH 代际命名空间 + x-bili-dsh-generation-owner 头 + pluginAgent==="dsh" + 主目的 + 非 side/count/responses + 非 egress + 无 pf-delta + openai/anthropic)。非 DSH 行为不变。头在 handle 入口提取后立即删除, 永不转发上游。回归风险低。

  6. 是否破坏缓存: 不破坏。复用父代折叠时保留父代 nextBlockId/nextRunId; 未验证 id 的 ref 座位保留 (dsh-reserved: 前缀), 消息 id 不可变性不变。CCR 见证 (witness.ccr) 在 adoptContentStore 时逐条盖戳, 供未来代际验证。

  7. 是否改了设计方向: 没有。本 PR 是 [PR] feat(dsh): route models between stock native and bili compaction #6123 的补充, 不改变架构方向。无 kernel 变更, 无新配置, 无迁移。

  8. 是否引入了新的配置: 没有。无新配置、无迁移、无自动修复。

合并判定

代码质量高, 保守 fail-closed, 测试充分, 回归风险低。 风格问题已顺手修。待新 CI (head b2a6a09373d) 完成后确认前一个 head 的 3 个 shard 失败是否复现 — 若复现则需排查贡献者新增 2 commit 的测试问题, 不阻塞本 PR 核心逻辑的审核结论。

注意: 本 PR 堆叠在 #6123 (draft) 上, 需先合 #6123 或 rebase 后才能合本 PR。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷

CI 更新 (head b2a6a09373d): 30 项检查完成, 5 个 test shard 失败 (ubuntu-22/2, ubuntu-22/3, ubuntu-24/2, ubuntu-24/3, windows-22/4), 0 pending。check-run 日志端点返回 404 (无法获取具体失败测试名)。

前一个 head e238b44b3f3 也有 3 个 shard 失败 (ubuntu-22/3, ubuntu-24/3, windows-22/4), 本次新增 ubuntu-22/2 和 ubuntu-24/2。失败 shard 在两次 run 间有变化, 可能是 flaky 也可能是贡献者新增 2 commit (24c20021a13 "Cover same-session title replays in the dedicated side-lane suite" + e238b44b3f3 "Use the platform temp directory and separator in DSH cold-restart coverage") 引入的测试问题。

本地定向验证 (head e39e7907a9c + 我的风格修复): typecheck 干净, 生产构建成功, 88/88 定向测试通过 (dsh-generation-reuse 12 + dsh-llm-stream-attribution 12 + plugin-fork 64)。

待办: 需获取 CI 日志确认失败的具体测试。若为 flaky, 重跑即可; 若为贡献者新增 commit 的测试问题, 需贡献者修复。不阻塞本 PR 核心逻辑的审核结论 (代码质量高, 保守 fail-closed, 回归风险低)。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

Re-verified the live check state first: at head e238b44b3f exactly 3 test shards are red (test ubuntu 24/3, windows 22/4, ubuntu 22/3; run 46807802444), 0 pending, every other gate green (lane-guard now passes). I fetched a failing shard's log and investigated the root cause.

Conclusion: the 3 red shards are an inherited MASTER bug, not a defect in this PR. I did not touch the PR branch (no push).

What is failing (all 3 shards, same signature)
tests/egress-session-footprint.test.ts → error: 'no such table: eg_debug' (confirmed in the job log: footprint fn at line 27, asserted at line 73, 2 occurrences).

Why it is a master bug, not a PR bug (verified against live master 230753fc)

  • The test was added to master on 2026-12-01 (commit 8baa4f3ea86 "fix(storage): report egress session rows and payload bytes") and references the table eg_debug in two places: the payloads map (line 22, eg_debug: ["inc_headers"]) and SELECT 1 FROM eg_debug WHERE session_id = 'target' (line 78).
  • That table was renamed eg_debug → egress_debug on 2026-11-30 (commit d9df7ba6ca1, owner ruling). The master schema creates egress_debug (src/storage/schema.ts:536); no code on master creates eg_debug (grep empty).
  • So the test queries a table that does not exist on master → it fails on master itself. This matches the author's report that it reproduces on unpatched master.
  • The PR does not touch the storage layer: git diff origin/master...HEAD -- src/storage/ is empty. A missing-table schema error cannot be caused by this PR.

Why the prescribed "merge origin/ci-fixes" action does not apply here
origin/ci-fixes is currently a stale snapshot — it is strictly an ancestor of master (head 8d196c74305, 2026-11-25, 0 unique commits; every ci-fixes commit is already on master; master is ~292 commits ahead). Merging it into the PR branch would bring in nothing new, so it cannot resolve this. The eg_debug→egress_debug test fix does not exist anywhere (not on master, not on ci-fixes).

Action / disposition

  • Did not modify the PR branch. Per the CI-coordination policy (2026-10-24), a master-level failure must be fixed on ci-fixes/master by the sentinel, not patched onto a PR branch.
  • The fix is mechanical: rename eg_debug → egress_debug in tests/egress-session-footprint.test.ts (2 places). It needs to land on master/ci-fixes. Once it does, this PR's CI goes green on re-run (CI merges the PR head with master).
  • This is a sentinel/master action item, not a PR defect. Stopping here rather than band-aiding the PR branch.

中文八问(结构化结论)

  1. 是什么问题:三个红 shard(ubuntu 24/3、windows 22/4、ubuntu 22/3)全部挂在同一个测试 tests/egress-session-footprint.test.ts,报 no such table: eg_debug。
  2. 什么原因导致的:继承自 master 的既有 bug,不是本 PR 引入的。该测试 2026-12-01 才加进 master(commit 8baa4f3ea86),两处引用旧表名 eg_debug(line 22 的 payloads 表 + line 78 的 SELECT 1 FROM eg_debug);而该表 2026-11-30 已按 owner 裁定改名 eg_debug→egress_debug(commit d9df7ba6ca1),master 的 schema 只建 egress_debug(src/storage/schema.ts:536),全 master 没有任何代码建 eg_debug。所以测试在 master 上本身就查一张不存在的表而失败。本 PR 的 git diff -- src/storage/ 为空,不可能造成缺表错误。
  3. 影响范围与严重程度:凡 CI 与当前 master 合并的 PR 都会踩中(测试在合并态里跑);master 自身 CI 也是红的。属 master 级红,非本 PR 特有。
  4. 怎么修复的:本 PR 分支未改、未 push。按 CI 协调政策(2026-10-24),master 级失败必须在 ci-fixes/master 上由哨兵收敛修复,不在 PR 分支上打补丁。修复本身是机械改名:测试里两处 eg_debug→egress_debug,需落到 master/ci-fixes;落地后本 PR 重跑即绿。
  5. 是否有回归问题:不涉及(本 PR 分支零改动)。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:不涉及。

关键事实补充:origin/ci-fixes 当前是过期快照(严格落后于 master,head 8d196c74305 2026-11-25,0 个独有提交,其全部提交都已在 master 上),所以政策规定的「merge ci-fixes」在此不适用——合进去不会带入任何新修复。eg_debug→egress_debug 的测试修复目前任何地方都不存在(master 没有、ci-fixes 也没有)。需哨兵/owner 在 master/ci-fixes 上补这个改名。

判定:本 PR 无缺陷,红 CI 源于 master 既有 bug;不在 PR 分支止血,停手等 master/ci-fixes 侧修复。

Resolve tsup.config.ts entry-array conflict: keep both the PR's dsh-native-compaction entry and master's inline-engine entry (KDD ranxianglei#26 dist chunking). Union resolution; build + typecheck verified locally.
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

Merge conflict resolved. The PR was 28 commits behind master with a single content conflict in tsup.config.ts. I merged origin/master (96e46fdcb58) into the PR branch and resolved the conflict by taking the union of both sides' entry arrays:

Both entry files exist in the merged tree, so both belong in the build. I chose merge (not rebase) because this branch's established pattern is to merge master in (prior "Merge origin/master" commits) and its history carries many merge commits — a rebase would replay all of them.

Verified locally before pushing:

  • Build succeeds — both dist/inline-engine.js and dist/agent/dsh-native-compaction.js are produced; dist-import-annotations: OK, dist-external: OK.
  • Typecheck passes (tsc --noEmit).
  • Conflict fully resolved — origin/master is now an ancestor of the new head, git merge-tree reports no conflicts, worktree clean.

Pushed as a fast-forward (no force): b2a6a09373d..9d2254759cf. The PR is now up-to-date with master and conflict-free.

CI note: the new head (9d2254759cf) will trigger a fresh CI run. The red test shards in the current mirror cache (5 shards) are the inherited egress-session-footprint master bug (no such table: eg_debug) I reported in my earlier comment — a master-level defect (the test references a table renamed on 2026-11-30), not a PR defect. I did not patch it onto this branch per the CI-coordination policy; it will persist on this PR's CI until fixed on master/ci-fixes.


中文八问(结构化结论)

  1. 是什么问题:PR 与 base 分支(master)冲突(merge state dirty),PR 无法合并。
  2. 什么原因导致的:PR 落后 master 28 个提交;双方在 tsup.config.ts 的 entry 数组各自独立追加了不同条目——PR 加 src/agent/dsh-native-compaction.ts([PR] feat(dsh): route models between stock native and bili compaction #6123 原生压缩入口),master 加 src/inline-engine.ts(KDD release v0.1.10 #26 dist chunking 入口)——git 无法自动合并同一行的两处独立追加,产生内容冲突。
  3. 影响范围与严重程度:仅阻塞本 PR 合并(mergeable=dirty);冲突在构建配置(入口数组),非运行时逻辑,无功能影响。
  4. 怎么修复的:把 origin/master(96e46fdcb58)merge 进 PR 分支(沿用该分支既有「merge master」模式,不 rebase)。冲突取并集:两个入口都保留(两文件在合并树里都存在、都该被构建)。本地验证 build 成功(两入口产物都生成)+ typecheck 通过 + merge-tree 无冲突 + master 已是新 head 祖先。fast-forward push(无 force)。
  5. 是否有回归问题:无——纯合并 + 入口数组并集,未改任何运行时逻辑;build/typecheck 通过;其余文件均自动合并干净。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:不涉及。

CI 说明:新 head(9d2254759cf)会触发新一轮 CI。当前镜像缓存里 5 个红 test shard 是之前已报告的 egress-session-footprint master 既有 bug(no such table: eg_debug,测试引用 2026-11-30 已改名的表),属 master 级缺陷、非本 PR 缺陷,按 CI 协调政策未在 PR 分支上打补丁;会在 master/ci-fixes 修复前持续出现在本 PR 的 CI 上。

判定:合并冲突已解决,PR 现与 master 同步、可合并;本 run 工作完成。

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DSH: first replay after a host generation change resends previously folded history

2 participants